package com.swyc.osschat.Test.IOTest.BIO;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @description TODO
 * @Author: z156940l@outlook.com
 * @className BaseTest
 * @Date: 2023/2/15 16:52
 */
public class BaseTest {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9000);
        while (true){
            System.out.println("等待连接。。。");
            Socket socketClient = serverSocket.accept();
            System.out.println("客户端发起连接。。。");
            handler(socketClient);
        }
    }

    private static void handler(Socket socketClient) throws IOException {
        byte[] bytes = new byte[1024];
        int read = socketClient.getInputStream().read(bytes);
        System.out.println("read完毕。。");
        if (read != -1){
            System.out.println("接收到客户端数据：" + new String(bytes, 0, read));
        }
        System.out.println("end");
    }
}
